package net.starwifi.duobao.hfg.refund;

import cn.com.hongpay.client.utils.Md5Encoder;
import cn.com.hongpay.client.utils.SignatureTools;
import net.starwifi.duobao.hfg.APIRequest;


/**
 * Created by STX on 2016/4/11.
 */
public class RefundRequest extends APIRequest {

    private String partner_trade_no;

    private Long refund_amount;

    private String refund_time;

    private String partner_id;

    private String partner_verify_code;

    private String request_time;

    private String signed_msg;

    public RefundRequest(String partner_trade_no, Long refund_amount, String refund_time, String partner_id, String partner_verify_code, String request_time) {
        this.partner_trade_no = partner_trade_no;
        this.refund_amount = refund_amount;
        this.refund_time = refund_time;
        this.partner_id = partner_id;
        this.partner_verify_code = Md5Encoder.encode(partner_verify_code+request_time);
        this.request_time = request_time;
    }

    @Override
    public String makeSign(String pfxFile, String pfxPwd, String privateKeyPwd) {
        StringBuffer sb=new StringBuffer();
        sb.append("partner_id:"+partner_id);
        sb.append(";partner_verify_code:"+partner_verify_code);
        sb.append(";refund_amount:"+refund_amount);
        sb.append(";refund_time:"+refund_time+";");

        SignatureTools st = new SignatureTools();
        String sign= st.sign(sb.toString(),"UTF-8",pfxFile, pfxPwd, privateKeyPwd);
        return sign;
    }

    @Override
    public String encode(String pfxFile, String pfxPwd, String privateKeyPwd) {
        signed_msg=makeSign(pfxFile,pfxPwd,privateKeyPwd);

        StringBuffer body=new StringBuffer();
        body.append("\"partner_trade_no\":\""+partner_trade_no+"\"");
        body.append(",\"refund_amount\":\""+refund_amount+"\"");
        body.append(",\"refund_time\":\""+refund_time+"\"");

        StringBuffer head=new StringBuffer();
        head.append("\"partner_id\":\""+partner_id+"\"");
        head.append(",\"partner_verify_code\":\""+partner_verify_code+"\"");
        head.append(",\"request_time\":\""+request_time+"\"");
        head.append(",\"signed_msg\":\""+signed_msg+"\"");

        String json="{\"body\":{"+body.toString()+"},\"head\":{"+head.toString()+"}}";
        return json;
    }


    public String getPartner_trade_no() {
        return partner_trade_no;
    }

    public void setPartner_trade_no(String partner_trade_no) {
        this.partner_trade_no = partner_trade_no;
    }

    public Long getRefund_amount() {
        return refund_amount;
    }

    public void setRefund_amount(Long refund_amount) {
        this.refund_amount = refund_amount;
    }

    public String getRefund_time() {
        return refund_time;
    }

    public void setRefund_time(String refund_time) {
        this.refund_time = refund_time;
    }

    public String getPartner_id() {
        return partner_id;
    }

    public void setPartner_id(String partner_id) {
        this.partner_id = partner_id;
    }

    public String getPartner_verify_code() {
        return partner_verify_code;
    }

    public void setPartner_verify_code(String partner_verify_code) {
        this.partner_verify_code = partner_verify_code;
    }

    public String getRequest_time() {
        return request_time;
    }

    public void setRequest_time(String request_time) {
        this.request_time = request_time;
    }

    public String getSigned_msg() {
        return signed_msg;
    }

    public void setSigned_msg(String signed_msg) {
        this.signed_msg = signed_msg;
    }
}
